﻿Public Class frmSettings

#Region "Commands"

    Private Sub cmdDefault_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDefault.Click
        txtIP.Text = "192.168.0.2"
        txtUsername.Text = "root"
        txtPassword.Text = "omron"
        txtMainDirectoryTarget.Text = "/tmp/UT"
        txtMainDirectoryHost.Text = ""
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        gVirtualMachine.strIP = txtIP.Text
        gVirtualMachine.strUsername = txtUsername.Text
        gVirtualMachine.strPassword = txtPassword.Text
        gVirtualMachine.strMainDirectory = txtMainDirectoryTarget.Text

        gVirtualMachine.Save(My.Application.Info.AssemblyName, "Settings")

        SaveSetting(My.Application.Info.AssemblyName, "Settings", "Host_MainDirectory", txtMainDirectoryHost.Text)

        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Private Sub cmdOpenMainDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpenMainDir.Click
        Try
            Dim oFolderBrowserDialog As New System.Windows.Forms.FolderBrowserDialog

            With oFolderBrowserDialog
                .RootFolder = Environment.SpecialFolder.Desktop
                .SelectedPath = PutSlash(GetInitDir(txtMainDirectoryHost.Text))
                .ShowNewFolderButton = False
            End With

            If oFolderBrowserDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtMainDirectoryHost.Text = oFolderBrowserDialog.SelectedPath
            End If

            oFolderBrowserDialog = Nothing
        Catch ex As Exception
            MsgBox("Error to open folder browser", MsgBoxStyle.Critical)
        End Try
    End Sub

#End Region

#Region "Events form"

    Private Sub me_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then
            Me.DialogResult = DialogResult.Cancel
        End If
    End Sub

    Private Sub frmVirtualMachineSettings_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtIP.Text = gVirtualMachine.strIP
        txtUsername.Text = gVirtualMachine.strUsername
        txtPassword.Text = gVirtualMachine.strPassword
        txtMainDirectoryTarget.Text = gVirtualMachine.strMainDirectory
        txtMainDirectoryHost.Text = GetSetting(My.Application.Info.AssemblyName, "Settings", "Host_MainDirectory", "")

        Dim oToolTip As New ToolTip
        oToolTip.SetToolTip(txtMainDirectoryHost, "For ex. D:\NJ-Robotics-Step2\SOURCES\TRUNK\Debug\motion\Robot")
        oToolTip.SetToolTip(txtMainDirectoryTarget, "Directory of UT")
        oToolTip = Nothing
    End Sub

#End Region

End Class